<template>
  <div id="app">
    <div style="width:50%" class="container">
      <div>
        <h3>Regist</h3>
        <h5>Email</h5>
        <input type="text" class="form-control" v-model="mail" /><br />
        {{mail}}
        <h5>Password</h5>
        <input type="password" class="form-control" v-model="password" /><br />
        {{password}}
        <h5>Gender</h5>
        <input type="radio" name="gender" v-model="gender" value="female" />男
        <input type="radio" name="gender" v-model="gender" value="male" />女<br />
        <h5>Hobby</h5>
        <input type="checkbox" name="hobby" v-model="hobby" value="music">音乐
        <input type="checkbox" name="hobby" v-model="hobby" value="movie">电影
        <input type="checkbox" name="hobby" v-model="hobby" value="sport">运动
        <br/>
        <button type="button" class="btn btn-success" @click="registfn">注册</button>
        <button type="button" class="btn btn-success" @click="registfn2">注册2</button>
      </div>
    </div>
  </div>
</template>

<script>
import Qs from 'qs' // 引入qs,主要是进行数据格式转换
export default {
  name: 'app',
  data () {
    return {
      mail: '',
      password: '',
      gender: '',
      hobby: ''
    }
  },
  methods: {
    registfn: function () {
      this.axios({
        method: 'get',
        url: 'http://localhost:8888/regist?mail=' + this.mail + '&password=' + this.password
      }).then(function (response) {
        console.log(response.data)
      })
    },
    // registfn2: function () { // 单独增加了一个按钮,主要是解决post请求中非body参数的传递
    //   this.axios({
    //     method: 'post',
    //     url: 'http://localhost:8090/regist',
    //     //用普通form表单的数据格式发送数据,因为默认情况下,axios post请求发送的数据是json格式的数据
    //     transformRequest: [function (data) {
    //       return Qs.stringify(data)
    //     }],
    //     data: {
    //       mail: this.mail,
    //       password: this.password
    //     }
    //   }).then(function (response) {
    //     console.log(response.data)
    //   })
    // }
  }
}
</script>
